#include <bits/stdc++.h>
using namespace std;
int t;
string s1, s2, s3;
int main()
{
    cin >> t;
    while (t--)
    {
        int flag = 0;
        cin >> s3 >> s2 >> s1;
        for (int i = 0; i < 4; i++)
        {
            map<char, int> mp; //内圈
            mp[s1[i]] += 1;    //中圈
            mp[s2[i]] += 1;
            mp[s2[i + 4]] += 1; //外圈
            mp[s3[i]] += 1;
            mp[s3[i + 4]] += 1;
            mp[s3[i + 8]] += 1;
            if (mp['Y'] != 1 || mp['R'] != 2 || mp['G'] != 3)
            {
                flag = 1;
                break;
            }
        }
        if (flag == 0)
            cout << "YES" << endl;
        else
        {
            cout << "NO" << endl;
        }
    }
    return 0;
}
